﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace parkour.Web_pages.Public_Pages
{
   public partial class Registration : System.Web.UI.Page
   {
      #region Variables
      #endregion

      #region Properties
      #endregion

      #region Functions

      protected void Page_Load(object sender, EventArgs e)
      {
         // For Testing - permission level returns 0 for some reason
         NumberSeatbelts.Text = Master.permission_level.ToString();

         if (Master.permission_level == 1)
            sqlVehicleType.SelectCommand = "get_vehicle_type_admin";
         else
            sqlVehicleType.SelectCommand = "get_vehicle_type_user";
      }

      /// <summary>
      /// Determines whether a user id is needed or not
      /// </summary>
      protected void DepartmentChanged(Object sender, EventArgs e)
      {
         if (Department.SelectedIndex < 3)
         {
            Users.Visible = true;
         }
         else
            Users.Visible = false;
      }

      /// <summary>
      /// Binds vehicle type to vehicle make
      /// </summary>
      protected void VehicleTypeChanged(Object sender, EventArgs e)
      {
         VehicleMake.DataBind();
      }

      /// <summary>
      /// Binds vehicle make to vehicle model
      /// </summary>
      protected void VehicleMakeChanged(Object sender, EventArgs e)
      {
         VehicleModel.DataBind();
      }



      #endregion

      #region Events
      /// <summary>
      /// Fills the registration class
      /// </summary>
      protected void Next_Click(object sender, EventArgs e)
      {
         Master.VehicleRegistration = new Classes.clsRegistrationInfo();
         if (Master.permission_level == 1)
            // This will pull the ID from the Admin's choice
            Master.VehicleRegistration.username = User.Text;
         else
            Master.VehicleRegistration.username = Master.user_ID;

         Master.VehicleRegistration.type_of_vehicle = Convert.ToInt32(VehicleType.SelectedValue);
         Master.VehicleRegistration.model = Convert.ToInt32(VehicleModel.SelectedValue); // Why is this convert but dept and insurance not
         Master.VehicleRegistration.color = Convert.ToInt32(AutomobileColor.SelectedValue);
         Master.VehicleRegistration.department_type = Department.SelectedValue;
         Master.VehicleRegistration.automobile_year = AutomobileYear.Text;
         Master.VehicleRegistration.license_plate = LicenseNumber.Text;
         Master.VehicleRegistration.state = RegistrationState.Text;
         Master.VehicleRegistration.insurance = Insurance.SelectedValue;
         Master.VehicleRegistration.seatbelts = NumberSeatbelts.Text;
         Master.VehicleRegistration.automobile_size = Convert.ToInt32(AutomobileSize.SelectedValue);
         Master.VehicleRegistration.time_of_registration = DateTime.Now;

         Response.Redirect("PickSpot.aspx");
      }
      #endregion

   }
}
